<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="80px"
  (onSearch)="queryData($event)"
  (onReset)="resetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-4">
  <div class="pagination-wrap-position table-wrap p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="180px" nzLeft>订单编号</th>
          <th nzAlign="center" nzWidth="150px">订单状态</th>
          <th nzAlign="center" nzWidth="150px">用户ID</th>
          <th nzAlign="center" nzWidth="160px">下单机型</th>
          <th nzAlign="center" nzWidth="170px">预估合计</th>
          <th nzAlign="center" nzWidth="170px">验机合计</th>
          <th nzAlign="center" nzWidth="260px">加价促销</th>
          <th nzAlign="center" nzWidth="170px">下单时间</th>
          <th nzAlign="center" nzWidth="170px">成交时间</th>
          <th nzAlign="center" nzWidth="170px">更新时间</th>
          <th nzAlign="center" nzWidth="200px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 订单编号 -->
          <td nzAlign="center" nzLeft>{{ data?.okey || '-' }}</td>

          <!-- 订单状态 -->
          <td nzAlign="center">
            <span
              *ngIf="data.ostat || data.ostat == 0"
              [ngStyle]="{'color': data.ostat | orderState: 'color'}">
              {{ data.ostat | orderState: 'text' }}
            </span>
          </td>

          <!-- 用户ID -->
          <td nzAlign="center">
            <ng-container *ngIf="data.userId;else templateUser">
              <a
                nz-button
                nzType="link"
                nzSize="small"
                [routerLink]="['/customer/tabs', data.userId, 0]"
                target="_blank"
              >{{ data.userId }}</a>
            </ng-container>
            <ng-template #templateUser>
              游客
            </ng-template>
          </td>

          <!-- 下单机型 -->
          <td nzAlign="center">{{ data.umname || '-' }}</td>

          <!-- 预估合计 -->
          <td nzAlign="center">
            {{ (data.uprc || 0) + (data.orderAprc || 0) + (data.cprc || 0) }}
            <span *ngIf="data.orderAprc || data.cprc">（含加价{{ (data.orderAprc || 0) + (data.cprc || 0) }}）</span>
          </td>

          <!-- 验机合计 -->
          <td nzAlign="center">
            <p [ngStyle]="{'color': ((data.bprc || 0) + (data.aprc || 0)) < ((data.uprc || 0) + (data.orderAprc || 0)) ? '#FF0000' : ''}">
              {{ (data.bprc || 0) + (data.aprc || 0) + (data.cprc || 0) }}
              <span *ngIf="data.aprc || data.cprc">（含加价{{ (data.aprc || 0) + (data.cprc || 0) }}）</span>
            </p>
          </td>

          <!-- 加价促销 -->
          <td nzAlign="center" nzBreakWord>
            <ng-container *ngIf="data.activityId;else templateActivity">
              <a
                style="color: #1890ff;"
                target="_blank"
                [routerLink]="['/aisi-recyc/loveMakeupPromotionDetails']"
                [queryParams]="{type: 2, id: data.activityId}"
                target="_blank"
              >{{ data.activityName || '-' }} [{{ data.activityId }}]</a>
            </ng-container>
            <ng-template #templateActivity>
              -
            </ng-template>
          </td>

          <!-- 下单时间 -->
          <td nzAlign="center">{{ data.otime11 || '-' }}</td>

          <!-- 成交时间 -->
          <td nzAlign="center">{{ data.otime19 || '-' }}</td>

          <!-- 更新时间 -->
          <td nzAlign="center">{{ data.updateTime || '-' }}</td>
          
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <a
              nz-button
              nzSize="small"
              nzType="link"
              target="_blank"
              [routerLink]="['/aisi-recyc/loveOrderDetails']"
              [queryParams]="{id: data.orderId}"
            >查看订单</a>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>